﻿using System;

/// <summary>
/// Summary description for DimensionCalc
/// </summary>
public class DimensionCalculation
{
    /*
     * List<string> lst = new List<string>();
     * lst.Add("12.4|12.4|3.5|0.12");
     * lst.Add("15.4|12.4|2.5|0.42");
     * lst.Add("12.4|14.4|3.5|0.12");
     * lst.Add("12.4|12.4|3.5|0.12");
     *  
     * Response.Write(DimensionCalculation.Calc(lst.ToArray()));
     * 
     */
    public static string Calc(string[] arrDimensions)
    {
        string sDimension = null;

        float length = 0;
        float width = 0;
        float height = 0;
        float weight = 0;

        try
        {
            for (int i = 0; i < arrDimensions.Length; i++)
            {
                float lth = 0;
                float wth = 0;
                float hgh = 0;
                float wgh = 0;

                string[] arrD = arrDimensions[i].Split('|');

                lth = float.Parse(arrD[0].Trim());
                wth = float.Parse(arrD[1].Trim());
                hgh = float.Parse(arrD[2].Trim());
                wgh = float.Parse(arrD[3].Trim());

                if (lth > length)
                {
                    length = lth;
                }

                if (wth > width)
                {
                    width = wth;
                }

                height += hgh;
                weight += wgh;
            }

            sDimension = length + "|" + width + "|" + height + "|" + weight;
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return sDimension;
    }
}